<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/WEB-INF/jsp/common/init.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<jsp:include page="/WEB-INF/jsp/common/common.jsp" />
	<jsp:include page="/WEB-INF/jsp_lib/validate.jsp" />
	<script type="text/javascript">
		$(function() {
			$("#form1").validate({
				rules : {
					'mac_codes' : {
						digits:true,
						required : true,
						minlength:9,
						maxlength:9
						
					},
					'note':{
						maxlength:255
					}
				}
			});
		});
		function isRepeat(arr){  
	     	var hash = {};  
	     	for(var i in arr) {  
	         	if(hash[arr[i]]){
	         		return true;  
	         	}
	         	hash[arr[i]] = true;  
	     	}  
	     	return false;  
	    }  
		function mySubmit() {
			var mac_codes = $("input[name='mac_codes']").val(); 
		    var mac = new Array(); 
		    var $codes = $("input[name='mac_codes']");
		    var flag = true;
			$.each($codes,function(i,n){
				if($codes.eq(i).val().length>0){
				  mac[i] = $codes.eq(i).val(); 
				}
			}); 
			if(isRepeat(mac)){
				alert("设备编号不可重复！");
				flag = false;
			}
			if(flag){
			 	$.ajax({
					type: "POST",
					url: "${path}/ix/mac/install/check_is_have.htm",
					data: "mac_codes="+mac_codes,
					cache: false,
					dataType:'json',
					success: function(msg){
						if(msg.result=="true"){
						  	$("#form1").submit();
						}else{
							ohSnap(msg.msg, "error");
						}
					}
				});
			}
		}
		function addMacCodes(){
			var obj = document.getElementById("tb_add");
			var curbr = document.createElement("br"); 
			obj.appendChild(curbr); 
			var curinput = document.createElement("input"); 
			curinput.setAttribute("name", "mac_codes");
			curinput.setAttribute("type", "text");
			curinput.setAttribute("maxlength", "100");
			curinput.setAttribute("style", "width:150px");
			obj.appendChild(curinput); 
		}
	</script>
</head>
<body>
	<jsp:include page="/WEB-INF/jsp_lib/tip.jsp" />
	<!-- 内容 -->
	<div>
		<form method="post" action="${path}/ix/mac/install/add.htm" id="form1">
			<h2>
				<div>印控仪录入</div>
			</h2>
			<table width="100%" class="lindex">
				<tr>
					<th align="right" style="min-width: 200px;">设备编号：</th>
					<td align="left" id="tb_add">
						<input name="mac_codes" type="text" maxlength="100" style="width: 150px"/>
						<a href="javascript:addMacCodes()" class="asave"><b>添加(+)</b></a><br/>
						<input name="mac_codes" type="text" maxlength="100" style="width: 150px"/><br/>
						<input name="mac_codes" type="text" maxlength="100" style="width: 150px"/>
					</td>
				</tr>
				<tr>
					<th align="right">备注信息：</th>
					<td align="left">
						<textarea name="note" rows="5" cols="50"></textarea>
					</td>
				</tr>
			</table>
			<div class="options">
				<a href="javascript:mySubmit();" class="asave"> 【保存】 </a>
			</div>
		</form>
	</div>
</body>
</html>